package com.prs.crm.dao.purchase.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.purchase.PurchaseReturnedDao;
import com.prs.crm.domain.purchase.FundsInBar;
import com.prs.crm.domain.purchase.PurchaseReturned;
import com.prs.crm.domain.purchase.PurchaseReturnedStoreOut;
import com.prs.crm.domain.stock.ProductStore;

public class PurchaseReturnedDaoImpl extends BaseDaoImpl<PurchaseReturned>
		implements PurchaseReturnedDao {

	@SuppressWarnings("unchecked")
	@Override
	public FundsInBar getFundsInBar(final String code) {	
		return (FundsInBar )getHibernateTemplate().execute(   
			      new HibernateCallback() {   
			        public Object doInHibernate(Session session) throws HibernateException {   
			        	Criteria criteria =  session.createCriteria(FundsInBar.class);
			        	criteria.add(Restrictions.eq("returnCode", code));	
			        	List<FundsInBar> result = criteria.list();
			        	if (result.size()>0){
			        		
			        		return result.get(0);
			        	}
			        	   
			        	else{			        		
			        		return null;
			        	}
			        }   
			      }   
			    );  
	}

	@SuppressWarnings("unchecked")
	@Override
	public PurchaseReturnedStoreOut getPurchaseReturnedStoreOut(final String code) {
		return (PurchaseReturnedStoreOut )getHibernateTemplate().execute(   
			      new HibernateCallback() {   
			        public Object doInHibernate(Session session) throws HibernateException {   
			        	Criteria criteria =  session.createCriteria(PurchaseReturnedStoreOut.class);
			        	criteria.add(Restrictions.eq("returnCode", code));	
			        	List<PurchaseReturnedStoreOut> result = criteria.list();
			        	if (result.size()>0){			        		
			        		return result.get(0);
			        	}
			        	   
			        	else{			        		
			        		return null;
			        	}
			        }   
			      }   
			    );  
	}

	

}
